from mediator import mediator
from mediator . tests . test_assistant import make_mediator_test_keyword_args

class filesystem_fake :
    def __init__ ( self ) :
        self . _create_file = [ ]
        self . _delete_file = [ ]
        self . _list_files = None
        self . _read_file_request = None
        self . _list_files_request = False
    def create_file ( self , name , contents ) :
        self . _create_file += [ [ name , contents ] ]
    def read_file_request ( self , name ) :
        self . _read_file_request = name
    def delete_file ( self , name ) :
        self . _delete_file += [ name ]
    def list_files_request ( self ) :
        self . _list_files_request = True

class mediator_filesystem_tests : 
    'mediator_filesystem'
    def __init__ ( self , test ) :
        self . _test = test
        self . _filesystem = filesystem_fake ( )
        self . _mediator = mediator ( )
        self . _mediator . register_modules ( ** make_mediator_test_keyword_args \
            ( 'filesystem' 
            , self . _filesystem
            , None
            ) )
    def test_create_file ( self ) :
        self . _mediator . create_file ( 'my file' , 'my contents' )
        self . _test . assume_equal ( self . _filesystem . _create_file , [ [ 'my file' , 'my contents' ] ] )
    def test_read_file_request ( self ) :
        self . _mediator . read_file_request ( 'my file' )
        self . _test . assume_equal ( self . _filesystem . _read_file_request , 'my file' )
    def test_delete_file ( self ) :
        self . _mediator . delete_file ( 'my file' )
        self . _test . assume_equal ( self . _filesystem . _delete_file , [ 'my file' ] )
    def test_list_files_request ( self ) :
        self . _mediator . list_files_request ( )
        self . _test . assume_true ( self . _filesystem . _list_files_request )
